/**
 * 
 */
package com.simtek.simplayer.entry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.net.Uri;

/**
 * @author Hitech
 * 
 */
public class VideoPlayEntry implements VideoTypeConstrant {
	protected byte					srcType;
	private String					videoSrc;
	private String					title;
	private String					uid;
	private List<VideoPlayEntry>	playlist;
	private List<YoutubeUrlMeta>	contentUrl;

	// play info
	private YoutubeUrlMeta			currentUrl;
	private int						playlistIndex;
	private int						playProgress;
	private boolean					isLoop;
	private boolean					isFailed = false;
	private Uri						dataUri;

	public List<YoutubeUrlMeta> getContentUrl() {
		return contentUrl;
	}

	public int getPlaylistIndex() {
		return playlistIndex;
	}

	public void setPlaylistIndex(int playlistIndex) {
		this.playlistIndex = playlistIndex;
	}

	public int getPlayProgress() {
		return playProgress;
	}

	public void setPlayProgress(int playProgress) {
		this.playProgress = playProgress;
	}

	public boolean isLoop() {
		return isLoop;
	}

	public void setLoop(boolean isLoop) {
		this.isLoop = isLoop;
	}

	public byte getSrcType() {
		return srcType;
	}

	public void setSrcType(byte srcType) {
		this.srcType = srcType;
	}

	public String getVideoSrc() {
		return videoSrc;
	}

	public void setVideoSrc(String videoSrc) {
		this.videoSrc = videoSrc;
	}

	public String getTitle() {
		return title;
	}

	public String getCurrentTitle() {
		if (isPlaylist()) {
			if (getCurrentEntry() != null) {
				return getCurrentEntry().getTitle();
			}
			return null;
		} else {
			return title;
		}
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<VideoPlayEntry> getPlaylist() {
		return playlist;
	}

	public void setPlaylist(List<VideoPlayEntry> playlist) {
		this.playlist = playlist;
	}

	public void addUrl(YoutubeUrlMeta meta) {
		if (contentUrl == null) {
			contentUrl = new ArrayList<YoutubeUrlMeta>();
		}
		contentUrl.add(meta);
		Collections.sort(contentUrl);
	}

	public VideoPlayEntry getCurrentEntry() {
		if (playlist == null) {
			return null;
		}

		try {
			return playlist.get(playlistIndex);
		} catch (Throwable e) {
			return null;
		}
	}

	public YoutubeUrlMeta getCurrentYoutubeUrl() {
		return currentUrl;
	}

	public void setCurrentUrl(YoutubeUrlMeta currentUrl) {
		this.currentUrl = currentUrl;
	}

	public boolean isPlaylist() {
		return playlist != null && !playlist.isEmpty();
	}

	public void setUri(Uri data) {
		this.dataUri = data;
	}

	public Uri getUri() {
		return dataUri;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public boolean isFailed() {
		return isFailed;
	}

	public void setFailed(boolean isFailed) {
		this.isFailed = isFailed;
	}
}
